$(document).ready(function() {
	$('.jsdroplist').each(function(){
		var droplist = $(this);
		var action = droplist.attr('action');
		var init = droplist.attr('init');
		var parent = droplist.attr('parent');
		if(parent == 'none'){
		}else{
			var id = $('#'+parent).attr('init');
			if(id==null || id=='')
				return false;
			action += '?id=' + id;
		}
		initList(droplist,action,init);
	});
});

function reloadSon(id,value){
	var droplist = $('#'+id);
	var action = droplist.attr('action');
	action += '?id=' + value;
	initList(droplist,action);
}

function initList(droplist,action,init){
	droplist.children().remove('.newadd');
	$.ajax({
		  url: action,
		  cache: false,
		  dataType:'json',
		  success: function(list){
		    for(var index in list){
		    	var data = list[index];
		    	var id = data['id'];
		    	var name = data['name'];
		    	if(init !=null && init == id)
		    		droplist.append('<option class="newadd" value="'+id+'" SELECTED>'+name+'</option>');
		    	else
		    		droplist.append('<option class="newadd" value="'+id+'">'+name+'</option>');
		    }
		    
		   
		}
		});
}